package com.yilin.platform.base_core.application;

import java.math.BigDecimal;

public class MathUtil {
    /**
     * 提供精确的小数位四舍五入处理，舍入模式采用用户指定舍入模式
     */
    public static double round(Object v, Integer scale, Integer round_mode) {
        if(scale==null)scale=2;
        if(round_mode==null)round_mode=BigDecimal.ROUND_HALF_EVEN;
        BigDecimal b = new BigDecimal(String.valueOf(v));
        return b.setScale(scale, round_mode).doubleValue();
    }
    public static double multiply(Double num1, Double num2) {
        if (num1 == null) num1 = 0.00;
        if (num2 == null) num2 = 0.00;
        BigDecimal decimal1 = new BigDecimal(String.valueOf(num1));
        BigDecimal decimal2 = new BigDecimal(String.valueOf(num2));
        return decimal1.multiply(decimal2).doubleValue();
    }


}
